<%--
  Created by IntelliJ IDEA.
  User: DELL
  Date: 2020/7/28
  Time: 20:21
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>sql-update</title>
</head>
<body>
员工编号:<input type="text" name="firstname" id="empno" value="">
<br>
<br>



ename:<input type="text" name="firstnumb" id="empname" value="NULL"><br>
job:<input type="text" name="firstname" id="empjob" value="NULL"><br>
mgr:<input type="text" name="firstnumb" id="empmgr" value="NULL"><br>
hiredate:<input type="text" name="firstname" id="emphiredate" value="NULL"><br>
sal:<input type="text" name="firstnumb" id="empsal" value="NULL"><br>
comm:<input type="text" name="firstname" id="empcomm" value="NULL"><br>
deptno:<input type="text" name="firstnumb" id="empdepyno" value="NULL"><br>

<button onclick="SQLupdate()">确定</button><br>
<button onclick="updateback()">返回主界面</button><br>
<script>
    //输入数据
    function SQLupdate() {
        var xmlhttp;
        if (window.XMLHttpRequest) {
            xmlhttp = new XMLHttpRequest();
        } else {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        console.log(xmlhttp);
        // 2. 发送Ajax请求
        xmlhttp.open("POST", "/test/SQLupdate", false);


        var text0=document.getElementById("empno");
        var text1=document.getElementById("empname");
        var text2=document.getElementById("empjob");
        var text3=document.getElementById("empmgr");
        var text4=document.getElementById("emphiredate");
        var text5=document.getElementById("empsal");
        var text6=document.getElementById("empcomm");
        var text7=document.getElementById("empdepyno");

        if(text0.value == "") {
            alert("empno is empty!!!");
            return false;
        }

        var person = {
            empno : text0.value,
            name: text1.value,
            job : text2.value,
            mgr: text3.value,
            hiredate : text4.value,
            sal: text5.value,
            comm : text6.value,
            deptno: text7.value,
        };
        var json = JSON.stringify(person);
        //alert(json);
        xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        xmlhttp.send(json);


        xmlhttp.open("GET", "/test/SQLupdateflag", true);
        xmlhttp.send();
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                var t = xmlhttp.responseText;
                alert(t);

            }
        };
    }

    //返回主界面
    function updateback() {
        window.location.href = "http://localhost:8080/test/6";
    }
</script>
</body>
</html>
